package com.ysq;

import java.util.*;

/**
 * 演示collections工具类的使用
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        test1();
    }


    public  static void  test1() {
       {
            List<String> list = new LinkedList<>();
            Collections.addAll(list, "147", "shuaige", "ysq","xixi");
            list.forEach(System.out::println);
            System.out.println("-------------------");
            //打乱集合的顺序
            Collections.shuffle(list);
            list.forEach(System.out::println);
        }
        System.out.println("-------------------");
        List<Integer> list =  new  LinkedList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        //按照倒叙给序列排序
        Collections.sort(list);
        list.forEach(System.out::println);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //安装倒序排
                return o2 - o1;
            }
        });
        System.out.println("------------");
        list.forEach(System.out::println);


            //让学生Student实现Comparable接口，这样也能给学生排序
            System.out.println("-------------------");
            List<Student> list1 = new ArrayList<>();
            list1.add(new Student("ysq", 22));
            list1.add(new Student("小帅", 27));
            list1.add(new Student("xixi", 25));

            Collections.sort(list1);
            list1.forEach(System.out::println);
            //讲了一系列Collections的方法
            //.............
        }
    }
